package com.njworkorder.HTSingleLogin;

import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.filter.AbstractRequestLoggingFilter;

import java.util.Set;

/**
 * @author ht
 * @since 2023/11/24 09:25
 */
public class MyLogFilter extends AbstractRequestLoggingFilter {
    private final Set<String> methodSet = Set.of("POST", "PUT", "DELETE", "post", "put", "delete");

    public MyLogFilter() {
        setIncludeClientInfo(true);
        setIncludePayload(true);
        setMaxPayloadLength(20480);
    }

    @Override
    protected void beforeRequest(HttpServletRequest request, String message) {
        if (methodSet.contains(request.getMethod())) {
            logger.info(message);
        }
    }

    @Override
    protected void afterRequest(HttpServletRequest request, String message) {
        if (methodSet.contains(request.getMethod())) {
            logger.info(message);
        }
    }
}
